/**
 * Created by dukes on 2015/10/28.
 */
//module game{
    class DecDetailPanel extends eui.Component{
        public constructor(){
            super();
            this.skinName = "skins.scene.DecDetailSkin";
        }
        private itemlist:eui.List;
        private img_close:eui.Image;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name == "itemlist"){
                this.itemlist = instance;
            }else if( name == "img_close" ){
                this.img_close = instance;
                this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.close, this);
            }
        }
        private listProvider:eui.ArrayCollection;
        public show(){
            DisplayController.instance().addToAlert(GameConst.GrayMask);
            DisplayController.instance().addToAlert(this);
            if( this.listProvider == null){
                this.listProvider = new eui.ArrayCollection();
                this.itemlist.dataProvider = this.listProvider;
                this.itemlist.itemRenderer = DecDetailItemRender;
            }
            var petid = PetMgr.getInstance().curPet.petId;
            var petdecs = Model.currentDecorators;
            var arr = [];
            var len = Model.currentDecorators.length;
            var dec:DecorateInfo;
            for(var i = 0; i < len; i++){
                dec = Model.currentDecorators[i];
                if( dec.petId == petid)
                    arr.push(dec);
            }
            // if( GuildMgr.getInstance().myGuildId != 0){
            //     var logo = GuildMgr.getInstance().guildLogo;
            //     if( logo.attrAttack != 0 ){
            //         arr.push([0,logo.attrAttack+logo.addtionAttack]);
            //     }
            //     if( logo.attrDefense != 0 ){
            //         arr.push([1,logo.attrDefense+logo.addtionDefense]);
            //     }
            // }
            this.listProvider.source = arr;
        }
        public close(evt:egret.TouchEvent){
            SoundMgr.getInstance().playEffect(SoundMgr.BTN);
            this.hide();
        }
        public hide(){
            DisplayController.instance().removeFromAlert(GameConst.GrayMask);
            DisplayController.instance().removeFromAlert(this);
        }

        public measure(){
            super.measure();
            this.x = GameConst.StageW - this.measuredWidth >> 1;
            this.y = GameConst.StageH - this.measuredHeight >> 1;
        }

        private static _instance:DecDetailPanel;
        public static getInstance():DecDetailPanel{
            if( DecDetailPanel._instance == null)
                DecDetailPanel._instance = new DecDetailPanel();
            return DecDetailPanel._instance;
        }
    }
//}